/**
 * 
 */
package com.mvc.service.vo.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.huangqj.classification.Pressure;
import org.huangqj.classification.Sugar;
import org.huangqj.classification.Weight;
import org.huangqj.consant.GlobalConstant;
import org.huangqj.consant.IdcardUtils;
import org.huangqj.consant.StringUtils;
import org.huangqj.consant.UrineBean_Ant;
import org.huangqj.consant.ValidatorUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.mvc.model.healthmanager.archive.Apparatus;
import com.mvc.model.healthmanager.archive.BloodOxygen;
import com.mvc.model.healthmanager.archive.BloodPressure;
import com.mvc.model.healthmanager.archive.BloodSugar;
import com.mvc.model.healthmanager.archive.Electrocardio;
import com.mvc.model.healthmanager.archive.Fat;
import com.mvc.model.healthmanager.archive.Temperature;
import com.mvc.model.healthmanager.archive.Urine;
import com.mvc.model.mb.archive.BaseInfo;
import com.mvc.model.report.ColligateReport;
import com.mvc.model.vo.*;
import com.mvc.model.vo.e100.v2.*;
import com.mvc.service.healthmanager.ApparatusService;
import com.mvc.service.healthmanager.PersonIdServiceI;
import com.mvc.service.vo.GetSonkaDataService;
import com.mvc.service.vo.TuserService;
import com.mvc.utils.Ch2PinYin;

/**
 * 对一体机出来的json数据进行封装处理
 * 
 * @author qingjie time:2015-09-16
 */
@Service
public class GetSonkaDataImpl implements GetSonkaDataService {
	@Autowired
	private ApparatusService aService;
	@Autowired
	private TuserService ts;
	@Autowired
	private PersonIdServiceI psi;

	private String idCard = null;
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	private SimpleDateFormat dateFormat_ = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private Map<String, String> params = new HashMap<String, String>();
	String fbg = "0.0";String ogtt = "0.0";String glu = "0.0";
	private String doctorCode = "administrator";
	private String contactDoctor = "超级管理员";
	@Override
	public SonkaData getData(String json) {
		System.err.println("getData--json:" + json);
		SonkaData sData = new SonkaData();
		if (!json.isEmpty()) {
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			jsonMap = JSON.parseObject(json.trim(), HashMap.class);
			// json to bean
			sData = JSON.parseObject(json, SonkaData.class);
			if(ValidatorUtil.isBlankOnString(sData.getIdCode())){
				sData.setIdCode(sData.getSFZ());
			}
			try {
				for (String key : jsonMap.keySet()) {
					String value = jsonMap.get(key) + "";
					if (key.equals("ImgBytes")
							|| value.indexOf("AAAAAAAAA") != -1) {
						continue;
					}
					if (key.equals("IdCode")) {
						idCard = jsonMap.get(key) + "";
					}
					System.out.println("key= " + key + "  and  value= "
							+ jsonMap.get(key));
					// 判断是否用户是否已经建档或者已经存在
				}
			} catch (Exception e) {
				e.printStackTrace();

			}
		}
		return sData;
	}

	@Override
	public <T> T returnObject(SonkaData sData, Class<T> cla, int i) {
		// 分类选择 1：基本信息、2：脂肪信息、3：血压信息、4：血糖信息、5：体重信息、6：血氧信息、7、心电信息 、8:心电图  9 体温 10 尿常规 11 胆固醇 12 血脂
		switch (i) {
		case 1:
			BaseInfo baseInfo = new BaseInfo();
			try {
				baseInfo.setName(sData.getName());
				baseInfo.setShortName(Ch2PinYin.getFirstCh(sData.getName()));
				baseInfo.setNickName(Ch2PinYin.getFirstCh(sData.getName()));
				baseInfo.setCheckCardId("000000000000");
				baseInfo.setCreateDate(new Date());
				baseInfo.setModifyDate(new Date());
				// baseInfo.setBirthDate(dateFormat.parse(sData.getBirthday()));
				baseInfo.setIdCardCode(sData.getSFZ());
				baseInfo.setAddress(sData.getAddress());
				baseInfo.setMobil(sData.getMobile());
				baseInfo.setSex(sData.getSex()==null?"3":(sData.getSex()=="1"?"1":"2"));
				baseInfo.setDataSource("安瑞科随访包");
				return (T) baseInfo;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 2:
			HealthFat healthFat = new HealthFat();
			try {
				healthFat.setDataSource("安瑞科随访包");
				healthFat.setUserHeight(ValidatorUtil.parseDoubleByString(sData.getHeight()));
				healthFat.setUserWeight(ValidatorUtil.parseDoubleByString(sData.getWeight()));
				healthFat.setUserAge(sData.getAge());
				healthFat.setFat(ValidatorUtil.parseDoubleByString(sData.getZhifanghl()));
				healthFat.setBmi(ValidatorUtil.parseDoubleByString(sData.getBmi()));
				healthFat.setWater(ValidatorUtil.parseDoubleByString(sData.getWater()));// 新的一体机无此项
				healthFat.setCreateDate(new Date());
				healthFat.setMeterDate(sData.getInDt()==null?dateFormat_.format(new Date()) : sData.getInDt());
				healthFat.setCardCode(sData.getSFZ());
				
				return (T) healthFat;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 3:
			HealthPressure healthPressure = new HealthPressure();
			try {
				healthPressure.setId((int) (Math.random() * 1000000));
				healthPressure.setCardCode(sData.getSFZ());
				healthPressure.setScDbpNow(ValidatorUtil.parseDoubleByString(sData.getHBooldPressure()));
				healthPressure.setScSbpNow(ValidatorUtil.parseDoubleByString(sData.getLBooldPressure()));
				healthPressure.setPluse(ValidatorUtil.parseIntByString(sData.getHeartRate()));// 心率
				healthPressure.setCreateDate(dateFormat.parse(ValidatorUtil.isNullOnString(sData.getInDt())?dateFormat.format(new Date()):sData.getInDt()));
				healthPressure.setModifyDate(dateFormat.format(new Date()));
				healthPressure.setDataSource("安瑞科随访包");
				return (T) healthPressure;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 4:
			HealthSugar healthSugar = new HealthSugar();
			try {

				healthSugar.setFbg(ValidatorUtil.parseDoubleByString(sData.getGLUC()));
				healthSugar.setOgtt(ValidatorUtil.parseDoubleByString(sData.getTwoGlu()));// 新的一体机无此项
				healthSugar.setCreateDate(new Date());
				healthSugar.setModifyDate(dateFormat.format(new Date()));
				healthSugar.setMeterDate(ValidatorUtil.isNullOnString(sData.getInDt())?dateFormat.format(new Date()):sData.getInDt());
				healthSugar.setCardCode(sData.getSFZ());
				healthSugar.setDataSource("安瑞科随访包");
				return (T) healthSugar;

			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 5:
			HealthWeight healthWeight = new HealthWeight();
			try {
				healthWeight.setMeter_date(sData.getInDt()==null?dateFormat.format(new Date()) : sData.getInDt());
				healthWeight.setCreate_date(new Date());
				healthWeight.setWeight(ValidatorUtil.parseDoubleByString(sData.getWeight()));
				healthWeight.setCard_code(sData.getSFZ());
				healthWeight.setDataSource("安瑞科随访包");
				healthWeight.setHeight(ValidatorUtil.parseDoubleByString(sData.getHeight()));
				healthWeight.setBmi(ValidatorUtil.parseDoubleByString(sData.getBmi()));
				healthWeight.setFollowUpDate(healthWeight.getMeter_date());
				healthWeight.setState(Weight.weightState(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getBmi())?"0.0":sData.getBmi()), ValidatorUtil.parseIntByString(sData.getSex()), ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getWaist())?"0.0":sData.getWaist()))+"");
				healthWeight.setMidefyDate(dateFormat_.format(new Date()));
				return (T) healthWeight;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 6:
			HealthBlood hBlood = new HealthBlood();
			try {
				hBlood.setMeterDate(sData.getInDt()==null?dateFormat.format(new Date()) : sData.getInDt());// 体检日期
				hBlood.setCreateDate(new Date());
				hBlood.setSpo2(sData.getSPO2());
				hBlood.setPulse(sData.getHeartRate()==null?0:Integer.parseInt(sData.getHeartRate()));
				hBlood.setPulse(ValidatorUtil.parseIntByString(sData.getHeartRate()));// 心率
				hBlood.setCardCode(sData.getSFZ());
				hBlood.setDataSource("安瑞科随访包");
				return (T) hBlood;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 7:
			HealthLink hLink = new HealthLink();
			try {
				hLink.setSubscribername(sData.getName());
				hLink.setCreateTime(dateFormat.parse(sData.getInDt()==null?dateFormat_.format(new Date()):sData.getInDt()));
				hLink.setRecordingTime(dateFormat_.format(new Date()));
				hLink.setReceivingTime(dateFormat_.format(new Date()));
				hLink.setDiagnosisTime(dateFormat_.format(new Date()));
				hLink.setCardCode(sData.getSFZ());
				hLink.setHeartRhythm(sData.getPulse());
				hLink.setDataSource("安瑞科随访包");
				return (T) hLink;
			} catch (Exception e) {
				e.printStackTrace();
			}
		case 8:
			Electrocardio ecg = new Electrocardio();
			try{
				ecg.setPersonName(sData.getName());
				ecg.setPersonAge(sData.getAge());
				ecg.setGender(sData.getSex().equals("1")?"1":"2");
				ecg.setCtrateDate(new Date());
				ecg.setHeaterate(sData.getHeartRate()==null?"0":sData.getHeartRate());
				ecg.setHeartPicture(sData.getD12HR()==null?"".getBytes():sData.getD12HR().getBytes());
				return (T) ecg;
			}catch (Exception e) {
				e.printStackTrace();
			}
		case 9:
			Temperature temp = new Temperature();
			try {
				temp.setDeviceCode("设备编号");
				temp.setCardCode(sData.getSFZ());
				temp.setTemperature(sData.getTemperature()==null?0.0 : Double.parseDouble(sData.getTemperature()));
				temp.setUploadTime(new Date());
				temp.setDataStatus(org.huangqj.classification.Temperature.tempState(ValidatorUtil.parseDoubleByString(sData.getTemperature())));
				temp.setDataSourse("安瑞科随访包");
				temp.setCreatedTime(new Date());
				temp.setModifyDate(new Date());
				return (T) temp;
			} catch (Exception e) {
				e.printStackTrace();
			}
		case 10:
			Urine urine = new Urine();
			try {
				urine.setDataSource("安瑞科随访包");
				urine.setCreateDate(ValidatorUtil.sdf.parse(sData.getInDt()));
				urine.setAgreement("3");
				String bil = StringUtils.getMapKeys(UrineBean_Ant.BilMap, sData.getBIL()+",", ",");
				String bld = StringUtils.getMapKeys(UrineBean_Ant.BldMap, sData.getBLD()+",", ",");
				String glu = StringUtils.getMapKeys(UrineBean_Ant.GluMap, sData.getGLU()+",", ",");
				String ket = StringUtils.getMapKeys(UrineBean_Ant.KetMap, sData.getKET()+",", ",");
				String leu = StringUtils.getMapKeys(UrineBean_Ant.LeuMap, sData.getLEU()+",", ",");
				String nit = StringUtils.getMapKeys(UrineBean_Ant.NitMap, sData.getNIT()+",", ",");
				String pro = StringUtils.getMapKeys(UrineBean_Ant.ProMap, sData.getPRO()+",", ",");
				String sg = StringUtils.getMapKeys(UrineBean_Ant.SgMap, sData.getSG()+",", ",");
				String ubg = StringUtils.getMapKeys(UrineBean_Ant.UbgMap, sData.getUBG()+",", ",");
				String vc = StringUtils.getMapKeys(UrineBean_Ant.VcMap, sData.getVC()+",", ",");
				String ph = StringUtils.getMapKeys(UrineBean_Ant.PhMap, sData.getPH()+",", ",");
				urine.setBil(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(bil)?"0":bil));
				urine.setBld(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(bld)?"0":bld));
				urine.setGlu(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(glu)?"0":glu));
				urine.setKet(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(ket)?"0":ket));
				urine.setLeu(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(leu)?"0":leu));
				urine.setNit(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(nit)?"0":nit));
				urine.setPro(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(pro)?"0":pro));
				urine.setSg(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(sg)?"0":sg));
				urine.setUbg(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(ubg)?"0":ubg));
				urine.setVc(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(vc)?"0":vc));
				urine.setPh(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(ph)?"0":ph));
				return (T) urine;
			} catch (Exception e) {
				e.printStackTrace();
			}
		case 11 :
			ColligateReport cr = new ColligateReport();
			try {
				cr.setDataSource("安瑞科随访包");
				cr.setCreateDate(ValidatorUtil.sdf.parse(sData.getInDt()));
				cr.setCreateCode(doctorCode);
				cr.setCreateMan(contactDoctor);
				cr.setReportTitle("");
				cr.setName(sData.getName());
				cr.setSex("1"==sData.getSex()?"男": "女");
				//cr.setSex(ead.getSex());
				cr.setAge(sData.getAge()+"");
				cr.setIdcard(sData.getSFZ());
				cr.setMobile(sData.getMobile());
				cr.setL_sbp(sData.getHBooldPressure());
				cr.setL_dbp(sData.getLBooldPressure());
				cr.setR_sbp(sData.getHBooldPressure());
				cr.setR_dbp(sData.getLBooldPressure());
				String sbpTimes = "0";String pNormalTimes = "0";String dbpTimes = "0";String controllerResult = "0";
				int pstate = Pressure.evaluation(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(cr.getL_sbp())?"0":cr.getL_sbp()), ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(cr.getL_dbp())?"0":cr.getL_dbp()));
				if(pstate == 2){
					sbpTimes = "1";pNormalTimes = "0";dbpTimes = "0";controllerResult = "0";
				}else if(pstate ==1){
					sbpTimes = "0";pNormalTimes = "1";dbpTimes = "0";controllerResult = "100%";
				}else{
					sbpTimes = "0";pNormalTimes = "0";dbpTimes = "1";controllerResult = "0";
				}
				cr.setpState(pstate ==2?"正常高值血压":(pstate ==1?"正常":"高压"));
				cr.setSbpTimes(sbpTimes);
				cr.setpNormalTimes(pNormalTimes);
				cr.setDbpTimes(dbpTimes);
				cr.setpControllerResult(controllerResult);
				cr.setpEff("");
				cr.setpAdvise("");
				cr.setFbg(sData.getGLU());
				cr.setOgtt(sData.getTwoGlu());
				cr.setGlu(glu);
				String fbgLow = "0";String fbgNomal = "0";String fbgHig = "0";String sControllerResult = "0";
				int sstate = Sugar.sugarState(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getGLUC())?"0.0":sData.getGLUC()), ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getTwoGlu())?"0.0":sData.getTwoGlu()));
				if(2 == sstate){
					fbgLow = "1";fbgNomal = "0";fbgHig = "0";sControllerResult = "0";
				}else if(1 == sstate){
					fbgLow = "0";fbgNomal = "1";fbgHig = "0";sControllerResult = "100%";
				}else{
					fbgLow = "0";fbgNomal = "0";fbgHig = "1";sControllerResult = "0";
				}
				cr.setsState(2 == sstate?"低血糖":(1 == sstate?"正常":"高血糖"));
				cr.setFbgLow(fbgLow);
				cr.setFbgNomal(fbgNomal);
				cr.setFbgHig(fbgHig);
				cr.setsControllerResult(sControllerResult);
				cr.setsEff("");
				cr.setsAdvice("");
				cr.setSpo2(sData.getSPO2());
				cr.setPlushMax(sData.getHeartRate());cr.setPlushMin(sData.getHeartRate());cr.setPlushAvg(sData.getHeartRate());
				cr.setSpo2Max(sData.getSPO2());cr.setSpo2Min(sData.getSPO2());cr.setSpo2Avg(sData.getSPO2());
				cr.setoAdvice("");
				cr.setHeight(sData.getHeight()+"");
				cr.setWaist(sData.getWaist());
				cr.setWeight(sData.getWeight()+"");
				cr.setHipline(sData.getHip());
				cr.setBmi(sData.getBmi()+"");
				cr.setWhr(sData.getWhr());
				cr.setTc(ValidatorUtil.isBlankOnString(sData.getChol())?sData.getTChol():sData.getChol());
				cr.setTg(sData.getTrig());
				cr.setUa(sData.getUa());
				cr.setTemperature(sData.getTemperature()+"");
				cr.setFat(sData.getFatRate()+"");
				cr.setBaseMetabolic(sData.getBasicMetabolism());
				cr.setPhysique(sData.getPhyN());
				cr.setShape(sData.getFaceN());
				cr.setAdvice("");
				cr.setHearerate(sData.getHeartRate());
				cr.setBmr(sData.getBasicMetabolism());
				return (T) cr;
			} catch (Exception e) {
				e.printStackTrace();
			}
		default:
			break;
		}
		return null;
	}

	@Override
	public <T> T returnR100Data(SonkaData sData, Class<T> cla, int i) {
		// 分类选择 1：基本信息、2：脂肪信息、3：血压信息、4：血糖信息、5：体重信息、6：血氧信息、7、心电信息 8 心电图 9 体温 10 尿酸  11 胆固醇 12 血脂
		switch (i) {
		case 1:
			BaseInfo baseInfo = new BaseInfo();
			try {
				if(!ValidatorUtil.isBlankOnString(sData.getIdCode())){
					if(ValidatorUtil.isBlankOnString(sData.getUserName())){
						sData.setUserName("未输入姓名");	
					}
					Apparatus apparatu = new Apparatus();
					Tuser tuser = new Tuser();
					apparatu.setNumber(sData.getHospitalNo());
					apparatu = aService.getApparatu(apparatu);
					if(apparatu!=null){
						doctorCode = apparatu.getReceiverCode();
						contactDoctor = apparatu.getReceiver();
						tuser = ts.getTuser(doctorCode);
						baseInfo.setPersonId(psi.getMaxStr(tuser.getUsercode()));
					}
					baseInfo.setName(sData.getUserName());
					baseInfo.setShortName(Ch2PinYin.getFirstCh(sData.getUserName()));
					baseInfo.setNickName(Ch2PinYin.getFirstCh(sData.getUserName()));
					baseInfo.setCreateDate(new Date());
					baseInfo.setModifyDate(new Date());
					baseInfo.setBirthDate(ValidatorUtil.sdf.parse(sData.getBirthday()));
					baseInfo.setIdCardCode(sData.getIdCode());
					baseInfo.setAddress(sData.getAddress());
					baseInfo.setMobil(sData.getMobile());
					baseInfo.setSex(IdcardUtils.getGenderByIdCard(sData.getIdCode())+"");
					baseInfo.setDoctorCode(doctorCode);
					baseInfo.setContactDoctor(contactDoctor);
					baseInfo.setFileState("0");
					baseInfo.setCreatfileMem(tuser.getName());
					baseInfo.setCreatfileMemId(tuser.getLoginname());
					baseInfo.setCreatfileDepId(tuser.getUsercode());
					baseInfo.setDataSource("一体机e100");
					//设置慢病信息
					params = new HashMap<String, String>();
					params.put("waist", sData.getWaist());params.put("height", sData.getHeight());
					params.put("weight", sData.getWeight());params.put("fat", sData.getFat());
					params.put("bmi", sData.getBmi());params.put("l_sbp", sData.getMaxBP());
					params.put("l_dbp", sData.getMinBP());params.put("r_sbp", sData.getMaxBP());
					params.put("r_dbp", sData.getMinBP());
					params.put("fbg", sData.getEmptyGlu());params.put("ogtt", sData.getTwoGlu());
					params.put("glu", sData.getGLU());params.put("tc", sData.getTChol());params.put("tg", sData.getTrig());
					baseInfo.setMbInfo(getMbInfo(params));
				}
				return (T) baseInfo;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 2:
			HealthFat healthFat = new HealthFat();
			try {
				if(!ValidatorUtil.isBlankOnString(sData.getFat())){
					healthFat.setUserAge(sData.getAge());
					healthFat.setUserHeight(ValidatorUtil.parseDoubleByString(sData.getHeight()));
					healthFat.setUserWeight(ValidatorUtil.parseDoubleByString(sData.getWeight()));
					healthFat.setFat(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getFat())?"0.0":sData.getFat()));
					healthFat.setBmi(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getBmi())?"0.0":sData.getBmi()));
					healthFat.setBmr(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getBasicMetabolism())?"0.0":sData.getBasicMetabolism()));
					healthFat.setWater(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getWater())?"0.0":sData.getWater()));
					healthFat.setCreateDate(new Date());
					healthFat.setMeterDate(sData.getMeasureTime()==null?dateFormat.format(new Date()) : sData.getMeasureTime());
					healthFat.setCardCode(sData.getIdCode());
					healthFat.setBranchno(sData.getBranchno());
					Apparatus apparatu = new Apparatus();
					apparatu.setNumber(sData.getHospitalNo());
					apparatu = aService.getApparatu(apparatu);
					String doctorCode = "administrator";
					if(apparatu!=null){
						doctorCode = apparatu.getReceiverCode();
					}
					healthFat.setDoctorCode(doctorCode);
					healthFat.setDataSource("一体机e100");
				}
				return (T) healthFat;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 3:
			HealthPressure healthPressure = new HealthPressure();
			try {
				if(!ValidatorUtil.isBlankOnString(sData.getMaxBP())&&!ValidatorUtil.isBlankOnString(sData.getMinBP())){
					healthPressure.setCardCode(sData.getIdCode());
					healthPressure.setScDbpNow(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getMaxBP())?"0.0":sData.getMaxBP()));
					healthPressure.setScSbpNow(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getMinBP())?"0.0":sData.getMinBP()));
					healthPressure.setPluse(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(sData .getPulse())?"0":sData .getPulse()));// 心率
					healthPressure.setCreateDate(dateFormat_.parse(sData.getMeasureTime()));
					healthPressure.setModifyDate(dateFormat.format(new Date()));
					healthPressure.setDataSource("一体机e100");
					healthPressure.setBranchno(sData.getBranchno());
				}
				return (T) healthPressure;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 4:
			HealthSugar healthSugar = new HealthSugar();
			try {
				if(!ValidatorUtil.isBlankOnString(sData.getEmptyGlu())||!ValidatorUtil.isBlankOnString(sData.getTwoGlu())){
					healthSugar.setFbg(Double.parseDouble((String) (sData.getEmptyGlu() == null|| sData.getEmptyGlu().equals("") ? "0.0" : sData.getEmptyGlu())));
					healthSugar.setOgtt(Double.parseDouble((String) (sData.getTwoGlu() == null|| sData.getTwoGlu().equals("") ? "0.0" : sData.getTwoGlu())));
					healthSugar.setCreateDate(dateFormat.parse(sData.getMeasureTime()));
					healthSugar.setMeterDate(sData.getMeasureTime());
					healthSugar.setCardCode(sData.getIdCode());
					healthSugar.setTc(ValidatorUtil.isBlankOnString(sData.getTChol())?0.0:Double.parseDouble(sData.getTChol()));
					healthSugar.setTg(ValidatorUtil.isBlankOnString(sData.getTrig())?0.0:Double.parseDouble(sData.getTrig()));
					healthSugar.setUa(ValidatorUtil.isBlankOnString(sData.getUa())?0.0:Double.parseDouble(sData.getUa()));
					healthSugar.setChol(ValidatorUtil.isBlankOnString(sData.getChol())?0.0:Double.parseDouble(sData.getChol()));
					healthSugar.setHdlChol(ValidatorUtil.isBlankOnString(sData.getHdlChol())?0.0:Double.parseDouble(sData.getHdlChol()));
					healthSugar.setCalChol(ValidatorUtil.isBlankOnString(sData.getCalcLdl())?0.0:Double.parseDouble(sData.getCalcLdl()));
					healthSugar.setDataSource("一体机e100");
					healthSugar.setBranchno(sData.getBranchno());
				}
				return (T) healthSugar;

			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 5:
			HealthWeight healthWeight = new HealthWeight();
			try {
				if(!ValidatorUtil.isBlankOnString(sData.getHeight())&&!ValidatorUtil.isBlankOnString(sData.getWeight())){
					healthWeight.setMeter_date(sData.getMeasureTime()==null?dateFormat.format(new Date()) : sData.getMeasureTime());
					healthWeight.setCreate_date(new Date());
					healthWeight.setCard_code(sData.getIdCode());
					healthWeight.setDataSource("一体机e100");
					healthWeight.setHeight(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getHeight())?"0.0":sData.getHeight()));
					healthWeight.setWeight(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getWeight())?"0.0":sData.getWeight()));
					healthWeight.setBmi(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getBmi())?"0.0":sData.getBmi()));
					healthWeight.setFollowUpDate(healthWeight.getMeter_date());
					healthWeight.setState(Weight.weightState(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getBmi())?"0.0":sData.getBmi()), ValidatorUtil.parseIntByString(IdcardUtils.getGenderByIdCard(sData.getIdCode())+""), ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(sData.getWaist())?"0.0":sData.getWaist()))+"");
					healthWeight.setMidefyDate(dateFormat_.format(new Date()));
					healthWeight.setWaist(ValidatorUtil.parseDoubleByString(sData.getWaist()));
					healthWeight.setHipline(ValidatorUtil.parseDoubleByString(sData.getHip()));
					healthWeight.setWhr(ValidatorUtil.parseDoubleByString(sData.getWhr()));
					healthWeight.setBranchno(sData.getBranchno());
				}
				return (T) healthWeight;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 6:
			HealthBlood hBlood = new HealthBlood();
			try {
				if(!ValidatorUtil.isBlankOnString(sData.getOxygen())){
					hBlood.setMeterDate(sData.getMeasureTime()==null?dateFormat_.format(new Date()) : sData.getMeasureTime());// 体检日期
					hBlood.setCreateDate(new Date());
					hBlood.setSpo2(ValidatorUtil.isBlankOnString(sData.getOxygen())?"":sData.getOxygen());
					hBlood.setPulse(ValidatorUtil.parseIntByString(ValidatorUtil.isBlankOnString(sData.getBpm())?"0":sData.getBpm()));// 心率
					hBlood.setCardCode(sData.getIdCode());
					hBlood.setDataSource("一体机e100");
					hBlood.setBranchno(sData.getBranchno());
				}
				return (T) hBlood;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 7:
			HealthLink hLink = new HealthLink();
			try {
				if(!ValidatorUtil.isBlankOnString(sData.getEcgHr())){
					hLink.setSubscribername(sData.getName());
					hLink.setCreateTime(dateFormat_.parse(sData.getMeasureTime()));
					hLink.setRecordingTime(dateFormat_.format(new Date()));
					hLink.setReceivingTime(dateFormat_.format(new Date()));
					hLink.setDiagnosisTime(dateFormat_.format(new Date()));
					hLink.setCardCode(sData.getIdCode());
					hLink.setHeartRhythm(ValidatorUtil.isBlankOnString(sData.getEcgHr())?"":sData.getEcgHr());
					hLink.setDataSource("一体机e100");
					hLink.setBranchno(sData.getBranchno());
				}
				return (T) hLink;
			} catch (Exception e) {
				e.printStackTrace();
			}
		case 8:
			Electrocardio ecg = new Electrocardio();
			try{
				if(!ValidatorUtil.isBlankOnString(sData.getEcgHr())){
					ecg.setHeartPicture(sData.getEcgData()==null?"".getBytes() : sData.getEcgData().getBytes());
					ecg.setPersonName(ValidatorUtil.isBlankOnString(sData.getUserName())?"":sData.getUserName());
					ecg.setPersonAge(ValidatorUtil.isNullOnIntger(sData.getAge())?0:sData.getAge());
					ecg.setGender(sData.getSex().equals("男")?"1":"2");
					ecg.setCtrateDate(new Date());
					ecg.setModifyDate(new Date());
					ecg.setHeaterate(ValidatorUtil.isBlankOnString(sData.getEcgHr())?"0":sData.getEcgHr());
				}
				return (T) ecg;
			}catch (Exception e) {
				e.printStackTrace();
			}
		case 9:
			Temperature temp = new Temperature();
			try {
				if(!ValidatorUtil.isBlankOnString(sData.getTemperature())){
					temp.setDeviceCode("设备编号");
					temp.setCardCode(sData.getIdCode());
					temp.setTemperature(ValidatorUtil.parseDoubleByString(sData.getTemperature()));
					temp.setUploadTime(new Date());
					temp.setDataStatus(org.huangqj.classification.Temperature.tempState(ValidatorUtil.parseDoubleByString(sData.getTemperature())));
					temp.setDataSourse("一体机e100");
					temp.setCreatedTime(new Date());
					temp.setModifyDate(new Date());
					temp.setBranchno(sData.getBranchno());
				}
				return (T) temp;
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		default:
			break;
		}
		return null;
	}
	
	@Override
	public <T> T returnE100Data(E100AllData ead, Class<T> cla, int i) {
		// 分类选择 1：基本信息、2：脂肪信息、3：血压信息、4：血糖信息、5：体重信息、6：血氧信息、7、心电信息 8 心电图 9 体温 10 尿酸  11 胆固醇 12 血脂
		switch (i) {
		case 1:
			BaseInfo baseInfo = new BaseInfo();
			if(!ValidatorUtil.isBlankOnString(ead.getBloodSugar())&&!ValidatorUtil.isBlankOnString(ead.getBloodsugarType())){
				bloodSugarInit(ead);
			}
			try {
				if(!ValidatorUtil.isBlankOnString(ead.getIdCode())){
					if(ValidatorUtil.isBlankOnString(ead.getName())){
						ead.setName("未输入姓名");	
					}
					Apparatus apparatu = new Apparatus();
					Tuser tuser = new Tuser();
					apparatu.setNumber(ead.getMachineId());
					apparatu.setState("1");
					apparatu = aService.getApparatu(apparatu);
					if(apparatu!=null){
						doctorCode = apparatu.getReceiverCode();
						contactDoctor = apparatu.getReceiver();
						tuser = ts.getTuser(doctorCode);
						baseInfo.setPersonId(psi.getMaxStr(tuser.getUsercode()));
					}
					baseInfo.setName(ead.getName());
					baseInfo.setShortName(Ch2PinYin.getFirstCh(ead.getName()));
					baseInfo.setNickName(Ch2PinYin.getFirstCh(ead.getName()));
					baseInfo.setCreateDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					baseInfo.setModifyDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					if(!ValidatorUtil.isBlankOnString(ead.getBirthday())){
						baseInfo.setBirthDate(ValidatorUtil.sdf.parse(ead.getBirthday()));
					}else{
						if(ead.getIdCode().length()==18){
							SimpleDateFormat sdf1=new SimpleDateFormat("yyyyMMdd");  //短日期格式
							baseInfo.setBirthDate(sdf1.parse(ead.getIdCode().substring(6, 14)));
						}
					}
					baseInfo.setIdCardCode(ead.getIdCode());
					baseInfo.setAddress(ead.getAddress());
					baseInfo.setMobil(ead.getMobile());
					baseInfo.setSex(IdcardUtils.getGenderByIdCard(ead.getIdCode())+"");
					baseInfo.setDoctorCode(doctorCode);
					baseInfo.setContactDoctor(contactDoctor);
					baseInfo.setFileState("0");
					baseInfo.setCreatfileMem(tuser.getName());
					baseInfo.setCreatfileMemId(tuser.getLoginname());
					baseInfo.setCreatfileDepId(tuser.getUsercode());
					baseInfo.setDataSource("一体机e100-v2.0");
					//设置慢病信息
					params = new HashMap<String, String>();
					params.put("waist", ead.getWaistline());
					params.put("height", ValidatorUtil.isNullOnDouble(ead.getHeight())?"":ead.getHeight()+"");
					params.put("weight", ValidatorUtil.isNullOnDouble(ead.getWeight())?"":ead.getWeight()+"");
					params.put("fat", ValidatorUtil.isNullOnDouble(ead.getFat())?"":ead.getFat()+"");
					params.put("bmi", ValidatorUtil.isNullOnDouble(ead.getBmi())?"":ead.getBmi()+"");
					params.put("l_sbp", ead.getHighPressure());
					params.put("l_dbp", ead.getLowPressure());
					params.put("r_sbp", ead.getHighPressure());
					params.put("r_dbp", ead.getLowPressure());
					params.put("fbg", fbg);params.put("ogtt", ogtt);
					params.put("glu", glu);params.put("tc", ead.getTChol());params.put("tg", ead.getTrig());
					baseInfo.setMbInfo(getMbInfo(params));
				}
				return (T) baseInfo;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 2:
			HealthFat healthFat = new HealthFat();
			try {
				if(!ValidatorUtil.isNullOnDouble(ead.getFatRate())||!ValidatorUtil.isNullOnDouble(ead.getFat())){
					healthFat.setUserAge(ValidatorUtil.parseIntByString(ead.getAge()));
					healthFat.setUserHeight(ead.getHeight());
					healthFat.setUserWeight(ead.getWeight());
					healthFat.setFatRate(ead.getFatRate());
					healthFat.setPhysique(ead.getPhysique());
					healthFat.setShape(ead.getShape());
					healthFat.setBmi(ead.getBmi());
					healthFat.setBmr(ValidatorUtil.parseDoubleByString(ead.getBasicMetabolism()));
					healthFat.setWater(ValidatorUtil.parseDoubleByString(ead.getWater()));
					healthFat.setCreateDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					healthFat.setMeterDate(ead.getMeasureTime());
					healthFat.setCardCode(ead.getIdCode());
					Apparatus apparatu = new Apparatus();
					apparatu.setNumber(ead.getMachineId());
					apparatu = aService.getApparatu(apparatu);
					String doctorCode = "administrator";
					if(apparatu!=null){
						doctorCode = apparatu.getReceiverCode();
					}
					healthFat.setDoctorCode(doctorCode);
					healthFat.setDataSource("一体机e100-v2.0");
					healthFat.setBranchno(ead.getBranchno());
				}
				return (T) healthFat;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 3:
			HealthPressure healthPressure = new HealthPressure();
			try {
				if(!ValidatorUtil.isBlankOnString(ead.getHighPressure())&&!ValidatorUtil.isBlankOnString(ead.getLowPressure())){
					healthPressure.setCardCode(ead.getIdCode());
					healthPressure.setScDbpNow(ValidatorUtil.parseDoubleByString(ead.getHighPressure()));
					healthPressure.setScSbpNow(ValidatorUtil.parseDoubleByString(ead.getLowPressure()));
					healthPressure.setPluse(ValidatorUtil.parseIntByString(ead .getPulse()));// 心率
					healthPressure.setCreateDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					healthPressure.setModifyDate(ead.getMeasureTime());
					healthPressure.setDataSource("一体机e100-v2.0");
					healthPressure.setBranchno(ead.getBranchno());
				}
				return (T) healthPressure;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;

		case 4:
			HealthSugar healthSugar = new HealthSugar();
			try {
				if(!ValidatorUtil.isBlankOnString(ead.getBloodSugar())){
					
					healthSugar.setFbg(Double.parseDouble(fbg));
					healthSugar.setOgtt(Double.parseDouble(ogtt));
					healthSugar.setGlu(Double.parseDouble(glu));
					healthSugar.setCreateDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					healthSugar.setMeterDate(ead.getMeasureTime());
					healthSugar.setCardCode(ead.getIdCode());
					healthSugar.setTc(ValidatorUtil.isBlankOnString(ead.getTChol())?0.0:Double.parseDouble(ead.getTChol()));
					healthSugar.setTg(ValidatorUtil.isBlankOnString(ead.getTrig())?0.0:Double.parseDouble(ead.getTrig()));
					healthSugar.setUa(ValidatorUtil.isBlankOnString(ead.getUa())?0.0:Double.parseDouble(ead.getUa()));
					healthSugar.setChol(ValidatorUtil.isBlankOnString(ead.getChol())?0.0:Double.parseDouble(ead.getChol()));
					healthSugar.setHdlChol(ValidatorUtil.isBlankOnString(ead.getHdlChol())?0.0:Double.parseDouble(ead.getHdlChol()));
					healthSugar.setCalChol(ValidatorUtil.isBlankOnString(ead.getCalcLdl())?0.0:Double.parseDouble(ead.getCalcLdl()));
					healthSugar.setDataSource("一体机e100-v2.0");
					healthSugar.setBranchno(ead.getBranchno());
				}
				return (T) healthSugar;

			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 5:
			HealthWeight healthWeight = new HealthWeight();
			try {
				if(!ValidatorUtil.isNullOnDouble(ead.getHeight())&&!ValidatorUtil.isNullOnDouble(ead.getWeight())){
					healthWeight.setMeter_date(ead.getMeasureTime());
					healthWeight.setCreate_date(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					healthWeight.setCard_code(ead.getIdCode());
					healthWeight.setDataSource("一体机e100-v2.0");
					healthWeight.setHeight(ead.getHeight());
					healthWeight.setWeight(ead.getWeight());
					healthWeight.setBmi(ead.getBmi());
					healthWeight.setFollowUpDate(healthWeight.getMeter_date());
					healthWeight.setState(Weight.weightState(ValidatorUtil.isNullOnDouble(ead.getBmi())?0.0:ead.getBmi(), ValidatorUtil.parseIntByString(IdcardUtils.getGenderByIdCard(ead.getIdCode())+""), ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(ead.getWaistline())?"0.0":ead.getWaistline()))+"");
					healthWeight.setMidefyDate(ValidatorUtil.dateFormat.format(new Date()));
					healthWeight.setWaist(ValidatorUtil.parseDoubleByString(ead.getWaistline()));
					healthWeight.setHipline(ValidatorUtil.parseDoubleByString(ead.getHipline()));
					healthWeight.setWhr(ValidatorUtil.parseDoubleByString(ead.getWhr()));
					healthWeight.setBranchno(ead.getBranchno());
				}
				return (T) healthWeight;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 6:
			HealthBlood hBlood = new HealthBlood();
			try {
				if(!ValidatorUtil.isBlankOnString(ead.getOxygen())){
					hBlood.setMeterDate(ead.getMeasureTime()==null?dateFormat_.format(new Date()) : ead.getMeasureTime());// 体检日期
					hBlood.setCreateDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					hBlood.setSpo2(ead.getOxygen());
					hBlood.setPulse(ValidatorUtil.parseIntByString(ead.getPulse()));// 心率
					hBlood.setCardCode(ead.getIdCode());
					hBlood.setDataSource("一体机e100-v2.0");
					hBlood.setBranchno(ead.getBranchno());
				}
				return (T) hBlood;
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		case 7:
			HealthLink hLink = new HealthLink();
			try {
				if(!ValidatorUtil.isBlankOnString(ead.getHr())){
					hLink.setSubscribername(ead.getName());
					hLink.setCreateTime(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					hLink.setRecordingTime(ead.getMeasureTime());
					hLink.setReceivingTime(ead.getMeasureTime());
					hLink.setDiagnosisTime(ead.getMeasureTime());
					hLink.setCardCode(ead.getIdCode());
					hLink.setHeartRhythm(ead.getPulse());
					hLink.setDataSource("一体机e100-v2.0");
				}
				return (T) hLink;
			} catch (Exception e) {
				e.printStackTrace();
			}
		case 8:
			Electrocardio ecg = new Electrocardio();
			try{
				if(!ValidatorUtil.isBlankOnString(ead.getHr())){
					ecg.setHeartPicture(ead.getEcgData()==null?"".getBytes() : ead.getEcgData().getBytes());
					ecg.setPersonName(ead.getName());
					ecg.setPersonAge(ValidatorUtil.parseIntByString(ead.getAge()));
					ecg.setGender(IdcardUtils.getGenderByIdCard(ead.getIdCode())+"");
					ecg.setCtrateDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					ecg.setModifyDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					ecg.setHeaterate(ead.getHr());
				}
				return (T) ecg;
			}catch (Exception e) {
				e.printStackTrace();
			}
		case 9:
			Temperature temp = new Temperature();
			try {
				if(!ValidatorUtil.isNullOnDouble(ead.getTemperature())){
					temp.setDeviceCode(ead.getMachineId());
					temp.setCardCode(ead.getIdCode());
					temp.setTemperature(ead.getTemperature());
					temp.setUploadTime(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					temp.setDataStatus(org.huangqj.classification.Temperature.tempState(ead.getTemperature()));
					temp.setDataSourse("一体机e100-v2.0");
					temp.setCreatedTime(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
					temp.setModifyDate(ValidatorUtil.sdf.parse(ead.getMeasureTime()));
					temp.setBranchno(ead.getBranchno());
				}
				return (T) temp;
			} catch (Exception e) {
				e.printStackTrace();
			}
		case 10:
			ColligateReport cr = new ColligateReport();
			try {
				cr.setDataSource("一体机e100-v2.0");
				cr.setCreateDate(ValidatorUtil.dateFormat.parse(ead.getMeasureTime()));
				cr.setCreateCode(doctorCode);
				cr.setCreateMan(contactDoctor);
				cr.setReportTitle("");
				cr.setName(ead.getName());
				cr.setSex("1"==ead.getSex()?"男": "女");
				//cr.setSex(ead.getSex());
				cr.setAge(ead.getAge());
				cr.setIdcard(ead.getIdCode());
				cr.setMobile(ead.getMobile());
				cr.setL_sbp(ead.getHighPressure());
				cr.setL_dbp(ead.getLowPressure());
				cr.setR_sbp(ead.getHighPressure());
				cr.setR_dbp(ead.getLowPressure());
				String sbpTimes = "0";String pNormalTimes = "0";String dbpTimes = "0";String controllerResult = "0";
				if(!ValidatorUtil.isBlankOnString(ead.getBloodPressureResult())){
					if(ead.getBloodPressureResult().equals("-1")){
						sbpTimes = "1";pNormalTimes = "0";dbpTimes = "0";controllerResult = "0";
					}else if(ead.getBloodPressureResult().equals("0")){
						sbpTimes = "0";pNormalTimes = "1";dbpTimes = "0";controllerResult = "100%";
					}else{
						sbpTimes = "0";pNormalTimes = "0";dbpTimes = "1";controllerResult = "0";
					}
					cr.setpState(ead.getBloodPressureResult().equals("-1")?"低压":(ead.getBloodPressureResult().equals("0")?"正常":"高压"));
				}else{
					cr.setpState("");
				}
				cr.setSbpTimes(sbpTimes);
				cr.setpNormalTimes(pNormalTimes);
				cr.setDbpTimes(dbpTimes);
				cr.setpControllerResult(controllerResult);
				cr.setpEff("");
				cr.setpAdvise("");
				cr.setFbg(fbg);
				cr.setOgtt(ogtt);
				cr.setGlu(glu);
				String fbgLow = "0";String fbgNomal = "0";String fbgHig = "0";String sControllerResult = "0";
				if(!ValidatorUtil.isBlankOnString(ead.getBloodSugarResult())){
					if(ead.getBloodSugarResult().equals("-1")){
						fbgLow = "1";fbgNomal = "0";fbgHig = "0";sControllerResult = "0";
					}else if(ead.getBloodSugarResult().equals("0")){
						fbgLow = "0";fbgNomal = "1";fbgHig = "0";sControllerResult = "100%";
					}else{
						fbgLow = "0";fbgNomal = "0";fbgHig = "1";sControllerResult = "0";
					}
					cr.setsState(ead.getBloodSugarResult().equals("-1")?"低血糖":(ead.getBloodSugarResult().equals("0")?"正常":"高血糖"));
				}else{
					cr.setsState("");
				}
				cr.setFbgLow(fbgLow);
				cr.setFbgNomal(fbgNomal);
				cr.setFbgHig(fbgHig);
				cr.setsControllerResult(sControllerResult);
				cr.setsEff("");
				cr.setsAdvice("");
				cr.setSpo2(ead.getOxygen());
				cr.setPlushMax(ead.getPulse());cr.setPlushMin(ead.getPulse());cr.setPlushAvg(ead.getPulse());
				cr.setSpo2Max(ead.getOxygen());cr.setSpo2Min(ead.getOxygen());cr.setSpo2Avg(ead.getOxygen());
				cr.setoAdvice("");
				cr.setHeight(ead.getHeight()+"");
				cr.setWaist(ead.getWaistline());
				cr.setWeight(ead.getWeight()+"");
				cr.setHipline(ead.getHipline());
				cr.setBmi(ead.getBmi()+"");
				cr.setWhr(ead.getWhr());
				cr.setTc(ValidatorUtil.isBlankOnString(ead.getChol())?ead.getTChol():ead.getChol());
				cr.setTg(ead.getTrig());
				cr.setUa(ead.getUa());
				cr.setTemperature(ead.getTemperature()+"");
				cr.setFat(ead.getFatRate()+"");
				cr.setBaseMetabolic(ead.getBasicMetabolism());
				cr.setPhysique(ead.getPhysique());
				cr.setShape(ead.getShape());
				cr.setAdvice("");
				cr.setHearerate(ead.getPulse());
				cr.setBmr(ead.getBasicMetabolism());
				return (T) cr;
			} catch (Exception e) {
				e.printStackTrace();
			}
		default:
			break;
		}
		return null;
	}

	@Override
	public List<SonkaData> returnDataByMobile(String json) {
		json = json.trim();
		List<SonkaData> list = new ArrayList<SonkaData>();
		if(!json.isEmpty()){
			list = JSON.parseArray(json,SonkaData.class);
		}
		return list;
	}

	@Override
	public E100AllData getE100AllData(String json) {
		E100AllData ead = new E100AllData();
		if (!json.isEmpty()) {
			InitClass ic = new InitClass();
			// json to bean
			ic = JSON.parseObject(json, InitClass.class);
			//属性拷贝
			//BeanUtils.copyProperties(ic, ead);
			ead.setMachineId(ic.getMachineId());
			ead.setMacAddr(ic.getMacAddr());
			ead.setRecordNo(ic.getRecordNo());
			ead.setMeasureTime(ic.getMeasureTime());
			ead.setLoginType(ic.getLoginType());
			ead.setDeviceType(ic.getDeviceType());
			//判断用户信息是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getMember())){
				Member member = JSON.parseObject(ic.getMember(), Member.class);
				BeanUtils.copyProperties(member, ead);
			}
			//判断人体成分 是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getFat())){
				Fat fat = JSON.parseObject(ic.getFat(), Fat.class);
				BeanUtils.copyProperties(fat, ead);
				ead.setFatResult(fat.getResult());
			}
			//判断人体成分是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getMinFat())){
				MinFat minFat = JSON.parseObject(ic.getMinFat(), MinFat.class);
				BeanUtils.copyProperties(minFat, ead);
				ead.setMinFatResult(minFat.getResult());
			}
			//判断血氧是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getBo())){
				BloodOxygen bo = JSON.parseObject(ic.getBo(), BloodOxygen.class);
				BeanUtils.copyProperties(bo, ead);
				ead.setBloodOxygenResult(bo.getResult());
			}
			//判断血压是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getBloodPressure())){
				BloodPressure bp = JSON.parseObject(ic.getBloodPressure(), BloodPressure.class);
				BeanUtils.copyProperties(bp, ead);
				ead.setBloodPressureResult(bp.getResult());
			}
			//判断单导心电是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getEcg())){
				Ecg ecg = JSON.parseObject(ic.getEcg(), Ecg.class);
				BeanUtils.copyProperties(ecg, ead);
				ead.setEcgResult(ecg.getResult());
			}
			//判断12 导心电是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getPEEcg())){
				PEEcg peEcg = JSON.parseObject(ic.getPEEcg(), PEEcg.class);
				BeanUtils.copyProperties(peEcg, ead);
			}
			
			//判断体温是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getTemperature())){
				Temperature temperature = JSON.parseObject(ic.getTemperature(), Temperature.class);
				BeanUtils.copyProperties(temperature, ead);
				ead.setTResult(temperature.getResult());
			}
			//判断腰臀比是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getWhr())){
				Whr whr = JSON.parseObject(ic.getWhr(), Whr.class);
				BeanUtils.copyProperties(whr,ead);
				ead.setWHResult(whr.getResult());
			}
			//判断血糖是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getBloodSugar())){
				BloodSugar bs = JSON.parseObject(ic.getBloodSugar(), BloodSugar.class);
				BeanUtils.copyProperties(bs, ead);
				ead.setBloodSugarResult(bs.getResult());
			}
			//判断血尿酸是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getUa())){
				Ua ua = JSON.parseObject(ic.getUa(), Ua.class);
				BeanUtils.copyProperties(ua, ead);
				ead.setUaResult(ua.getResult());
			}
			
			//判断总胆固醇是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getChol())){
				Chol chol = JSON.parseObject(ic.getChol(), Chol.class);
				BeanUtils.copyProperties(chol, ead);
			}
			//判断血脂是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getBloodFat())){
				BloodFat bf = JSON.parseObject(ic.getBloodFat(), BloodFat.class);
				BeanUtils.copyProperties(bf,ead);
				ead.setBloodFatResult(bf.getResult());
			}
			//判断心血管功能是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getCardiovascular())){
				Cardiovascular cardiovascular = JSON.parseObject(ic.getCardiovascular(), Cardiovascular.class);
				BeanUtils.copyProperties(cardiovascular, ead);
				ead.setCResult(cardiovascular.getResult());
			}
			//判断骨密度是否为空
			if(!ValidatorUtil.isBlankOnString(ic.getBmd())){
				BMD bmd = JSON.parseObject(ic.getBmd(), BMD.class);
				BeanUtils.copyProperties(bmd, ead);
				ead.setBMDResult(bmd.getResult());
			}
		}
		return ead;
	}
	
	public String getMbInfo(Map<String, String> params){
		MbInfo mi = new MbInfo();
		mi.setWaist(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("waist"))?"0.0":params.get("waist")));
		mi.setHeight(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("height"))?"0.0":params.get("height")));
		mi.setWeight(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("weight"))?"0.0":params.get("weight")));
		mi.setFat(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("fat"))?"0.0":params.get("fat")));
		mi.setBmi(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("bmi"))?"0.0":params.get("bmi")));
		mi.setL_sbp(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("l_sbp"))?"0.0":params.get("l_sbp")));
		mi.setR_sbp(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("r_sbp"))?"0.0":params.get("r_sbp")));
		mi.setL_dbp(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("l_dbp"))?"0.0":params.get("l_dbp")));
		mi.setR_dbp(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("r_dbp"))?"0.0":params.get("r_dbp")));
		mi.setFbg(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("fbg"))?"0.0":params.get("fbg")));
		mi.setOgtt(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("ogtt"))?"0.0":params.get("ogtt")));
		mi.setGlu(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("glu"))?"0.0":params.get("glu")));
		mi.setTc(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("tg"))?"0.0":params.get("tc")));
		mi.setTg(ValidatorUtil.parseDoubleByString(ValidatorUtil.isBlankOnString(params.get("tg"))?"0.0":params.get("tg")));
		return JSON.toJSONString(mi);
	}

	//初始化血糖数据
	public void bloodSugarInit(E100AllData ead){
		switch (ValidatorUtil.parseIntByString(ead.getBloodsugarType())) {
		case 1:
			fbg = ead.getBloodSugar();
			break;
		case 2:
			ogtt = ead.getBloodSugar();
			break;
		case 3:
			glu = ead.getBloodSugar();
			break;
		default:
			break;
		}

	}
}
